1 using UnityEngine;
2 using System.Collections;
3
4 public class CrossyCharacterMoveScript : MonoBehaviour {
5
6 private GameObject jumpPoint1;
7 private GameObject jumpPoint2;
8 private GameObject jumpPoint3;
9 private GameObject jumpPoint4;
10 private GameObject jumpPoint5;
11 private GameObject jumpPoint6;
12 private Vector3 JumpTargetLocation;
13 private float JumpMidPointLocation;
14 public float jumpHeightIncrement = 10;
15
16 public float jumpSpeed = 20;
17 private float initialJumpHeight;
18
19 private bool isJumping = false;
20
21
22 int currentJumpPointNumber;
23 // Use this for initialization
24 void Start () {
25 jumpPoint1 = GameObject.Find ("jumpPoint1");
26 jumpPoint2 = GameObject.Find ("jumpPoint2");
27 jumpPoint3 = GameObject.Find ("jumpPoint3");
28 jumpPoint4 = GameObject.Find ("jumpPoint4");
29 jumpPoint5 = GameObject.Find ("jumpPoint5");
30 jumpPoint6 = GameObject.Find ("jumpPoint6");
31
32 currentJumpPointNumber = 1;
33
34 this.transform.position = new Vector3 (jumpPoint1.transform.position.x, this.transform.position.y, this.transform.position.z);
35
36 }
37
38 // Update is called once per frame
39 void Update () {
40 if (Input.GetMouseButtonDown (0)) {
41 if(!isJumping)
42 {
43 StartJump ();
44 }
45 }
46
47 if (isJumping) {
48 this.transform.position = new Vector3(this.transform.position.x - jumpSpeed * Time.deltaTime, this.transform.position.y, this.transform.position.z);
49 if(this.transform.position.x < JumpTargetLocation.x)
50 {
51 isJumping = false;
52 this.transform.position = new Vector3(this.transform.position.x, initialJumpHeight, this.transform.position.z);
53
54 }
55 if(isJumping)
56 {
57 if(this.transform.position.x > JumpMidPointLocation) {
58 this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
59 }
60 else {
61 this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y - jumpHeightIncrement * Time.deltaTime, this.transform.position.z);
62 }
63 }
64 }
65 }
66
67 void StartJump()
68 {
69 isJumping = true;
70 currentJumpPointNumber += 1;
71 if (currentJumpPointNumber > 6) {
72 currentJumpPointNumber = 1;
73 }
74
75 switch (currentJumpPointNumber) {
76 case 1:
77 // don't jump, reset to location 1
78 this.transform.position = new Vector3(jumpPoint1.transform.position.x, jumpPoint1.transform.position.y, this.transform.position.z);
79 isJumping = false;
80 break;
81 case 2:
82 JumpTargetLocation = jumpPoint2.transform.position;
83 //this.transform.position = new Vector3(jumpPoint2.transform.position.x, this.transform.position.y, this.transform.position.z);
84 break;
85 case 3:
86 JumpTargetLocation = jumpPoint3.transform.position;
87 //this.transform.position = new Vector3(jumpPoint3.transform.position.x, this.transform.position.y, this.transform.position.z);
88 break;
89 case 4:
90 JumpTargetLocation = jumpPoint4.transform.position;
91 //this.transform.position = new Vector3(jumpPoint4.transform.position.x, this.transform.position.y, this.transform.position.z);
92 break;
93 case 5:
94 JumpTargetLocation = jumpPoint5.transform.position;
95 //this.transform.position = new Vector3(jumpPoint5.transform.position.x, this.transform.position.y, this.transform.position.z);
96 break;
97 case 6:
98 JumpTargetLocation = jumpPoint6.transform.position;
99 //this.transform.position = new Vector3(jumpPoint6.transform.position.x, this.transform.position.y, this.transform.position.z);
100 break;
101 default:
102 break;
103 }
104 initialJumpHeight = JumpTargetLocation.y;
105 JumpMidPointLocation = JumpTargetLocation.x + ((this.transform.position.x - JumpTargetLocation.x) / 2);
106 if (currentJumpPointNumber % 2 == 0) {
107 JumpMidPointLocation += 0.5f;
108 } else {
109 JumpMidPointLocation -= 0.5f;
110 }
111
112 }
113 }